package com.dlm.service.impl;

import com.dlm.dao.UserCoupon;
import com.dlm.dao.Users;
import com.dlm.service.IUserCouponService;
import com.dlm.service.IUsersService;
import com.jfinal.plugin.activerecord.Page;
import org.apache.log4j.Logger;

/**
 * Created by chongsong on 15/3/17.
 * song316@gmail.com
 */
public class UsersServiceImpl implements IUsersService {
    private Logger logger = Logger.getLogger(UsersServiceImpl.class);
    @Override
    public void updateTel(long tel, String openId) throws Exception {
        Users users = findUserByOpenid(openId);
        if (users != null) {
            users.set(Users.tel, tel);
            users.update();
        } else {
            logger.error("更新用户手机号失败!");
        }
    }

    @Override
    public Users findUserByOpenid(String openid){
        try {
            String selSql = "SELECT u.* FROM users u WHERE u.openid = '" + openid + "'";
            return Users.dao.findFirst(selSql);
        } catch (Exception e) {
            return null;
        }
    }
}
